var CopyLinkNameAndURLOverlay = {

Init:function ()
{
    var nsSS = Components.interfaces.nsISupportsString;
    document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", CopyLinkNameAndURLOverlay.linkPopup,true);
    
    var tabbarMenu = gBrowser.mStrip.firstChild.nextSibling;
    var separator = null;
    tabbarMenu.insertBefore(document.getElementById("clnu-tabbar-context"), separator);
    tabbarMenu.addEventListener("popupshowing", CopyLinkNameAndURLOverlay.tabbarPopup,true);

	var oPref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.");
	var ss = Components.classes[ "@mozilla.org/supports-string;1" ].createInstance(nsSS);
	ss.data = document.getElementById("clnu-link-context").getAttribute('statustext');
	oPref.setComplexValue("copylinknameandurl@livemylife.cn.description", nsSS, ss);
},

linkPopup:function ()
{
	document.getElementById("clnu-link-context").hidden = (!gContextMenu.onLink);
},
tabbarPopup:function ()
{
    var aTab = (gBrowser && gBrowser.mContextTab && (gBrowser.mContextTab.localName == "tab") ? gBrowser.mContextTab : null);
    document.getElementById("clnu-tabbar-context").hidden = (aTab == null);
},

    CopyOnLink:function ()
    {
        var urlname = gContextMenu.linkText();
        var url = 'getLinkURL' in gContextMenu ? gContextMenu.getLinkURL() : gContextMenu.linkURL();
        Components.classes['@mozilla.org/widget/clipboardhelper;1'].getService(Components.interfaces.nsIClipboardHelper).copyString(urlname+" "+url);
    },
    CopyOnTab:function ()
    {
        var aTab = (gBrowser && gBrowser.mContextTab && (gBrowser.mContextTab.localName == "tab") ? gBrowser.mContextTab : null);
        var urlname = aTab.linkedBrowser.contentDocument.title;
        var url  = aTab.linkedBrowser.contentDocument.location.href;
        Components.classes['@mozilla.org/widget/clipboardhelper;1'].getService(Components.interfaces.nsIClipboardHelper).copyString(urlname+' '+url);
    }
}
window.addEventListener("load", CopyLinkNameAndURLOverlay.Init,true);
